home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 176-200 / scopedisk192 / unzipv3.1 / mapname.c < prev    next >
C/C++ Source or Header  |  1995-03-19  |  5KB  |  162 lines

  1. /*
  2.  mapname.c  for unzip v3.05
  3.  
  4.  Change DEC-20, VAX/VMS, DOS style filenames into normal Unix names.
  5.  Almost ALL the code is from good old xxu, Author:  F. da Cruz, CUCCA
  6.  
  7.  We're assuming, of course, that someday somebody will be creating
  8.  files on DECs and VAX/VMS systems, of course.
  9.  
  10.  Usage: set the "-m" switch on the unzip command line.
  11.  
  12.  Action: Renames argument files as follows:
  13.    strips Unix and PKZIP DOS path name from front (up to rightmost '/')
  14.    if present.
  15.    strips DEC device:, node:: names from front (up to rightmost ':')
  16.    if present.  (This also takes care of any DOS drive: artifacts.)
  17.    strips DEC-20 <directory> or VMS [directory] name if present
  18.    strips DEC-20 version number from end (everything after 2nd dot) if present
  19.    strips VMS generation number from end (everything after ';') if present
  20.    lowercases any uppercase letters
  21.    honors DEC-20 CTRL-V quote for special characters
  22.    discards unquoted unprintable characters
  23.  
  24.    Returns non-0 if filename zeroed out.
  25.  
  26.  Author:  David Kirschbaum, 25 Apr 90
  27.  
  28.  27 Apr 90: Reports indicate something's SERIOUSLY wrong.  When -m switch
  29.  is enabled, it gobbles digits in file names!  Sigh ... Fixed.
  30.  Sloppy testing.
  31.  David Kirschbaum
  32.  
  33.  25 Apr 90:  Bill Davidsen did some tweaking.  v3.05
  34.  
  35. */
  36.  
  37. #ifndef UNIX
  38. #ifndef STRSIZ
  39. #define STRSIZ 256
  40. #endif
  41. #endif
  42.  
  43. #include <stdio.h>
  44.  /* this is your standard header for all C compiles */
  45. #include <ctype.h>
  46. #include <stdio.h>
  47. #include "unzip.h"
  48. #include "zip_proto.i"
  49. #ifdef UNIX
  50.  
  51. /* On some systems the contents of sys/param.h duplicates the
  52.    contents of sys/types.h, so you don't need (and can't use)
  53.    sys/types.h. */
  54.  
  55. #include <sys/types.h>
  56. #endif
  57.  
  58. #ifdef __STDC__
  59.  
  60. #include <string.h>
  61.  /* this include defines strcpy, strcmp, etc. */
  62. #endif
  63.  
  64.  
  65. extern char filename[];        /* in unzip.c */
  66. extern int mflag;
  67.  
  68. mapped_name()
  69. {
  70.     char name[13];            /* File name buffer (long enough
  71.                          * for a DOS filename) */
  72.     char *pp, *cp, *xp;            /* Character pointers */
  73.     char delim = '\0';            /* Directory Delimiter */
  74.     int dc = 0;                /* Counters */
  75.     int quote = 0;            /* Flags */
  76.     int indir = 0;
  77.     int done = 0;
  78.     register int workch;        /* hold the character being tested */
  79.  
  80.  
  81.     xp = filename;        /* Copy pointer for simplicity */
  82. #ifdef MAP_DEBUG
  83.     fprintf(stderr,"%s ",*xp);    /* Echo name of this file */
  84. #endif
  85.     pp = name;            /* Point to translation buffer */
  86.     *name = '\0';        /* Initialize buffer */
  87.     dc = 0;            /* Filename dot counter */
  88.     done = 0;            /* Flag for early completion */
  89.  
  90.     for (cp = xp; workch = *cp++; ) { /* Loop thru chars... */
  91.  
  92.     if (quote) {        /* If this char quoted.. */
  93.         *pp++ = workch;    /*  include it literally. */
  94.         quote = 0;
  95.         }
  96.     else if (indir) {    /* If in directory name.. */
  97.         if (workch == delim)
  98.         indir = 0;    /* look for end delimiter. */
  99.         }
  100.         else switch (workch) {
  101.         case '<':        /* Discard DEC-20 directory name */
  102.         indir = 1;
  103.         delim = '>';
  104.         break;
  105.         case '[':        /* Discard VMS directory name */
  106.         indir = 1;
  107.         delim = ']';
  108.         break;
  109.         case '/':        /* Discard Unix path name.. */
  110.         case '\\':        /*  or MS-DOS path name.. */
  111.         case ':':       /*  or DEC dev: or node:: name */
  112.         pp = name;
  113.         break;
  114.         case '.':        /* DEC -20 generation number
  115.                  * or MS-DOS type */
  116.         if (++dc == 1)    /* Keep first dot */
  117.             *pp++ = workch;
  118.         else        /* Discard everything starting */
  119.             done = 1;    /* with second dot. */
  120.         break;
  121.         case ';':        /* VMS generation or DEC-20 attrib */
  122.         done = 1;    /* Discard everything starting with */
  123.         break;        /* semicolon */
  124.         case '\026':    /* Control-V quote for special chars */
  125.         quote = 1;    /* Set flag for next time. */
  126.         break;
  127.         default:        /* some other char */
  128.         if(isdigit(workch))    /* v2.0k '0'..'9' */
  129.             *pp++ = workch;    /* v2.0k accept them, no tests */
  130.         else{
  131.             if(mflag){        /* if -m switch.. */
  132.                 if (isupper(workch)) /* Uppercase letter to lowercase */
  133.                         workch = tolower(workch);
  134.             }
  135.             if (workch == ' ')  /* change blanks to underscore */
  136.                 *pp++ = '_';
  137.             else if (isprint(workch)) /* Other printable, just keep */
  138.                 *pp++ = workch;
  139.         }
  140.     }  /* switch */
  141.     }  /* for loop */
  142.     *pp = '\0';                /* Done with name, terminate it */
  143.  
  144.     /* We COULD check for existing names right now,
  145.      * create a "unique" name, etc.
  146.      * However, since other unzips don't do that...
  147.      * we won't bother.  Maybe another day, ne?
  148.      * If this went bad, the name'll either be nulled out
  149.      * (in which case we'll return non-0)
  150.      * or following procedures won't be able to create the
  151.      * extracted file, and other error msgs will result.
  152.      */
  153.  
  154.     if(*name == '\0'){
  155.     fprintf(stderr,"conversion of [%s] failed\n",filename);
  156.     return(0);
  157.     }
  158.     strcpy(filename,name);    /* copy converted name into global */
  159.     return(1);
  160. }
  161.  
  162.